package com.smartao.base.employee;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.stereotype.Service;

import com.smartao.core.dao.BaseDao;
import com.smartao.core.orm.Page;
import com.smartao.core.orm.PageRequest;
import com.smartao.core.service.BaseEntityService;

@Service
public class EmployeeServiceImpl extends BaseEntityService<Employee, Long> implements EmployeeService{

	@Autowired
	private EmployeeDao employeeDao;
	@Autowired
	private EmployeeMapper employeeMapper;
	@Autowired
	private PasswordEncoder passwordEncoder;
	
	@Override
	protected BaseDao<Employee, Long> getDao() {
		return employeeDao;
	}
	
	/**
	 * 用户登录验证接口
	 */
	@Override
	public Employee findUserByAccount(String account) {
		return employeeDao.findByAccount(account);
	}

	@Override
	public List<Employee> findByDepartment(Long id) {
		return employeeDao.findByDepartment(id);
	}

	@Override
	public Long countByDepartment(Long id) {
		return employeeDao.countByDepartment(id);
	}
	
	@Override
	public void updateAccount(Long employeeId, String account, String password) {
		password = passwordEncoder.encodePassword(password, null);
		employeeDao.updateAccount(employeeId, account, password);
	}

	@Override
	public List<Employee> findByIds(Long[] ids) {
		return employeeDao.findByIds(ids);
	}

	@Override
	public Page<Employee> pageQuery(Employee employee,PageRequest pageRequest) {
		return employeeMapper.pageQuery(employee,pageRequest);
	}

}
